﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using Pub;
using LZQXT.Test.Forms.Tree;
using LZQXT.Test.Forms.DB;
using JT_DBTree;

//using Raize.CodeSiteLogging;


namespace LZQXT.Test.Forms
{
    public partial class FDBTree : Form
    {

        const int I_TYPE_ADD = 1;
        const int I_TYPE_DEL = 3;
        const int I_TYPE_EDT = 2;

        public static FDBInit fdbinit;
        public static FDBInit_Add fdbinit_add;

        public static ADOTest ado1 = new ADOTest();
        public static ADOTest ado2 = new ADOTest();

        public CGridViewMenu gridMenu1;

        List<Button> btnTab = new List<Button>();
        List<Button> btnCtrl = new List<Button>();
        CTree ctree = new CTree();
        //int i_gridView_sta = 0;
        //int i_treeNode_sta = 0;
        Label[] lab;
        List<object> lst1 = new List<object>();
        String[] sP_ID;
        String[] sTabData;
        String sTarget = "";
        int Tab_Index = 0;
        TextBox[] tbox;

        public int I_ID = 0;
        public DataSet ds1;
        public DataSet ds2;
        FDBRow fdbrow;

        DBTreeInfo treeInfo = new DBTreeInfo();

        public FDBTree()
        {
            InitializeComponent();

            fdbinit = new FDBInit();
            fdbinit_add = new FDBInit_Add();
        }


        /// <summary>
        /// 执行sql语句，显示表格数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnTabClick(object sender, EventArgs e)
        {
            Tab_Index = Convert.ToInt32(((Button)sender).Tag);
            if (sTarget.Length == 0)
            {
                dataGridView1.DataSource = null;
                return;
            }

            refChildTab_grid();
        }

        /// <summary>
        /// 子表数据编辑事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Click(object sender, EventArgs e)
        {
            int i_btn = 0;

            if (sender is Int32) i_btn = Convert.ToInt32(sender);
            if (sender is MenuItem) i_btn = Convert.ToInt32(((MenuItem)sender).Tag);
            if (sender is ToolStripMenuItem) i_btn = Convert.ToInt32(((ToolStripMenuItem)sender).Tag);
            if (sender is Button) i_btn = Convert.ToInt32(((Button)sender).Tag);
            if (sender is ToolStripButton) i_btn = Convert.ToInt32(((ToolStripButton)sender).Tag);

            CDebug.EnterMethod("事件处理");
            try
            {
                switch (i_btn)
                {
                    case 1:     //fill TreeView
                        //treeView1.Nodes.Clear();


                        if (treeView1.SelectedNode != null)
                        {
                            treeView1.SelectedNode.Nodes.Clear();
                            ctree.fillTreeView(treeView1, (TreeNodeDBMgr)treeView1.SelectedNode);
                        }
                        //else
                        //{
                        //    treeView1.Nodes.Clear();
                        //    ctree.fillTreeView(treeView1, null);
                        //}

                        break;

                    case 10:        //add node
                        if (CPub.MsgBox("确定要添加新的数据到数据库吗？", "添加"))
                        {
                            for (int i = 0; i < ado1.ds.Tables[0].Rows.Count; i++)
                            {
                                if (tbox[0].Text == ado1.ds.Tables[0].Rows[i][0].ToString())
                                {
                                    CPub.MsgBox("编号已'" + tbox[0].Text + "'存在");
                                    return;
                                }
                            }
                            DataRow dr = ado1.ds.Tables[0].NewRow();
                            for (int i = 0; i < tbox.Length; i++)
                            {
                                dr[i] = tbox[i].Text;
                            }
                            ado1.ds.Tables[0].Rows.Add(dr);
                            ado1.update(ADOTest.I_ADD);
                        }
                        break;
                    case 11:        //edit node
                        if (CPub.MsgBox("确定要写入到数据库吗？", "修改"))
                        {
                            for (int i = 0; i < tbox.Length; i++)
                            {
                                ado1.ds.Tables[0].Rows[0][i] = tbox[i].Text;
                            }
                            ado1.update(ADOTest.I_EDT);
                        }
                        break;
                    case 12:       //delete node
                        if (CPub.MsgBox("确定要写入到数据库吗？", "删除"))
                        {
                            ado1.ds.Tables[0].Rows[0].Delete();
                            ado1.update(ADOTest.I_DEL);
                        }
                        break;
                    case 13:        //refresh node
                        btn_Click(1, null);
                        break;
                    case 20:    //add node
                        if (CPub.MsgBox("确定要写入到数据库吗？", "添加"))
                        {
                            if (dataGridView1.Rows.Count > 0)
                            {
                                int i = ado2.ds_count;
                                DataRow dr = ado2.ds.Tables[0].NewRow();
                                for (int j = 0; j < ado2.ds.Tables[0].Columns.Count; j++)
                                {
                                    dr[j] = dataGridView1.Rows[i].Cells[j].Value;
                                }
                                ado2.ds.Tables[0].Rows.Add(dr);
                                ado2.update(ADOTest.I_ADD);
                            }
                        }
                        break;
                    case 21:    //edit node
                        if (CPub.MsgBox("确定要写入到数据库吗？", "修改"))
                        {
                            if (dataGridView1.Rows.Count > 0)
                            {
                                for (int i = 0; i < ado2.ds.Tables[0].Rows.Count; i++)
                                {
                                    for (int j = 0; j < ado2.ds.Tables[0].Columns.Count; j++)
                                    {
                                        ado2.ds.Tables[0].Rows[i][j] = dataGridView1.Rows[i].Cells[j].Value;
                                    }
                                }
                                ado2.update(ADOTest.I_EDT);
                            }
                        }
                        break;
                    case 22:    //delete node
                        if (CPub.MsgBox("确定要写入到数据库吗？", "删除"))
                        {
                            if (dataGridView1.SelectedRows.Count > 0)
                            {
                                int r_Count = dataGridView1.SelectedRows.Count;
                                for (int i = 0; i < r_Count; i++)
                                {
                                    ado2.ds.Tables[0].Rows[dataGridView1.SelectedRows[0].Index].Delete();
                                }
                                ado2.update(ADOTest.I_DEL);
                            }
                        }
                        break;

                    case 31:    //打开新树目录
                        try
                        {
                            string sDBCon = "";
                            FTreeLogin fdblogin = new FTreeLogin();
                            CDB.DBInfo dbInf = new CDB.DBInfo();
                            fdblogin.ShowDialog(ref sDBCon, ref treeInfo, ref dbInf);
                            if (sDBCon != null && sDBCon != "")
                            {
                                ado1.S_Con = sDBCon;
                                ado2.S_Con = sDBCon;

                                //填充树目录
                                CDebug.EnterMethod("填充树目录");
                                TreeNodeDBMgr node0 = new TreeNodeDBMgr();
                                sTabData = treeInfo.sTabDataNameS.Split(';');
                                sP_ID = treeInfo.sTabDataIDS.Split(';');
                                node0.sTabName = treeInfo.sTabName;
                                node0.sPreCol = treeInfo.sPreCol;
                                node0.sIDCol = treeInfo.sIDCol;
                                node0.sName = treeInfo.sName;
                                node0.sTagID = treeInfo.sTagID;
                                node0.sOrderID = treeInfo.sOrderID;
                                node0.sRootID = treeInfo.sRootID;
                                node0.sTabDataNameS = treeInfo.sTabDataNameS;
                                node0.sTabDataIDS = treeInfo.sTabDataIDS;

                                node0.Text = "[" + dbInf.sSourc + "][" + dbInf.sDBNam + "][" + dbInf.sTable + "][" + treeInfo.sCaption + "]";
                                node0.dbInf = dbInf;
                                node0.Tag = treeInfo.sRootID;
                                node0.ImageIndex = 3;
                                node0.i_Typ = 0;

                                CDebug.EnterMethod("生成树");
                                ctree.fillTreeView(treeView1, node0);
                                CDebug.ExitMethod("生成树");

                                CDebug.EnterMethod("填充树");
                                treeView1.Nodes.Add(node0);
                                CDebug.ExitMethod("填充树");

                                CDebug.ExitMethod("填充树目录");

                                //填充右键菜单
                                CDebug.EnterMethod("填充右键菜单");
                                fill_Item(treeInfo);
                                CDebug.ExitMethod("填充右键菜单");

                                //与目录树关联的其它表
                                CDebug.EnterMethod("与目录树关联的其它表");
                                int btn_left = 5;
                                int btn_top = 5;
                                int panel_Height = 35;
                                if (btnTab != null && btnTab.Count > sTabData.Length)
                                {
                                    for (int i = btnTab.Count - 1; i >= sTabData.Length - 1; i--)
                                    {
                                        btnTab[i].Dispose();
                                        btnTab.RemoveAt(i);
                                    }
                                }

                                for (int i = 0; i < sTabData.Length; i++)
                                {
                                    if (btnTab.Count <= i || btnTab[i] == null)
                                    {
                                        Button btn_tem = new Button();
                                        btn_tem.Click += new EventHandler(btnTabClick);     //创建按钮后关联事件
                                        btn_tem.Tag = i;
                                        btn_tem.Parent = panel5;

                                        btnTab.Add(btn_tem);
                                    }

                                    if (btnTab[i].Text != sTabData[i])
                                    {
                                        btnTab[i].Text = sTabData[i];
                                    }


                                    btnTab[i].Width = 155;
                                    btnTab[i].Height = 25;



                                    if (btn_left + btnTab[i].Width > panel5.Width)
                                    {
                                        btn_left = 5;
                                        btn_top += 27;
                                        panel_Height = btn_top + 30;
                                    }

                                    btnTab[i].Top = btn_top;
                                    btnTab[i].Left = btn_left;

                                    btn_left += 160;

                                }

                                panel5.Height = panel_Height;
                                CDebug.ExitMethod("与目录树关联的其它表");
                            }
                        }
                        catch (System.Exception ex)
                        {
                            CDebug.SendError(ex.ToString());
                            MessageBox.Show(ex.Message);
                        }
                        break;
                    case 32:    //close ado
                        //treeView1.Nodes.Clear();
                        if (treeView1.SelectedNode != null && ((TreeNodeDBMgr)treeView1.SelectedNode).i_Typ == 0)
                            treeView1.SelectedNode.Remove();
                        break;
                    case 33:    //refresh ado
                        btn_Click(1, null);
                        break;
                    case 34:
                        FTreeEdit fdbtree = new FTreeEdit();
                        fdbtree.ShowDialog();
                        break;
                }
            }
            catch (System.Exception ex)
            {
                CDebug.SendError(ex.ToString());
            }
            CDebug.ExitMethod("事件处理");
        }

        private void FGSMA_P_Class_Load(object sender, EventArgs e)
        {
            treeView1.Dock = DockStyle.Fill;
            dataGridView1.Dock = DockStyle.Fill;
            tabControl1.Dock = DockStyle.Fill;
            tboxBtnSQL.Dock = DockStyle.Fill;
            tabControl1.SelectedIndex = 0;

            //设置字段编辑窗口为FDBRow();
            panelNode.Dock = DockStyle.Fill;
            fdbrow = new FDBRow();
            fdbrow.TopLevel = false;
            fdbrow.Parent = panelNode;
            fdbrow.FormBorderStyle = FormBorderStyle.None;
            fdbrow.Dock = DockStyle.Fill;
            fdbrow.i_typ_edit = FDBRow.i_TYP_EDIT_TREE;
            fdbrow.Show();

            gridMenu1 = new CGridViewMenu(dataGridView1, ado2);

        }

        private void Form_Add(Form form1, TabPage tabPage1)
        {
            form1.TopLevel = false;
            form1.Parent = tabPage1;
            form1.FormBorderStyle = FormBorderStyle.None;
            form1.Dock = DockStyle.Fill;
            form1.Show();
        }

        /// <summary>
        /// 打开文件夹
        /// </summary>
        private void openDir()
        {
            string sID = Convert.ToString(treeView1.SelectedNode.Tag);
            ADOTest ado1 = new ADOTest();
            DataSet ds1 = ado1.sel1("select * from GSMA_P_Class where id=" + sID);
            if (!CPub.dsIsNull(ds1))
            {
                string sPath = CPub.webPath + ds1.Tables[0].Rows[0]["path"].ToString();
                CPub.Send(sPath);
                CPub.runExe("Explorer.exe", sPath.Replace(@"/", @"\"));
            }
        }

        /// <summary>
        /// 填充选中节点对应的子表数据
        /// </summary>
        private void refChildTab_grid()
        {
            CDebug.EnterMethod("执行语句，显示关系表数据");
            try
            {
                dataGridView1.DataSource = null;

                String strSQL2 = sP_ID[Tab_Index];
                DataSet ds1 = getSelectNode();
                strSQL2 = getChildTab_SQL(ds1, strSQL2);    // 将sql中的变量替换为对应的数值
                strSQL2 = strSQL2.Replace("{0}", sTarget);
                tboxBtnSQL.Text = strSQL2;
                string sTabNam_temp = CPub.findStrBetween(strSQL2.Replace("\n", " ").ToLower(), "from", "").Trim();
                string sTabNam_temp_2 = CPub.findStrBetween(sTabNam_temp, "", " ");
                if (sTabNam_temp_2 != "") gridMenu1.sTableName = sTabNam_temp_2;
                else gridMenu1.sTableName = sTabNam_temp;
                gridMenu1.strSQL_Def = strSQL2;

                try
                {
                    ds2 = ado2.sel1(strSQL2);
                    CDebug.Send(strSQL2 + "\n--返回结果个数: " + ado2.ds_count);
                    dataGridView1.DataSource = ds2.Tables[0];
                }
                catch (System.Exception ex)
                {
                    dataGridView1.DataSource = null;
                    CDebug.SendError(ex.ToString());
                }
            }
            catch (System.Exception ex)
            {
                CDebug.SendError(ex.ToString());
            }
            CDebug.ExitMethod("执行语句，显示关系表数据");

        }

        private string getChildTab_SQL(DataSet ds1, string strSQL)
        {
            if (!CDB.dsIsNull(ds1))
            {
                for (int i = 0; i < ds1.Tables[0].Columns.Count; i++)
                {
                    string s_c = ds1.Tables[0].Columns[i].Caption.ToUpper();
                    string s_v = ds1.Tables[0].Rows[0][i].ToString();
                    strSQL = strSQL.ToUpper().Replace("{" + s_c + "}", s_v);
                }
            }
            return strSQL;
        }

        private void refChildTabName_btn()
        {
            TreeNodeDBMgr node1 = (TreeNodeDBMgr)treeView1.SelectedNode;
            string sID = Convert.ToString(treeView1.SelectedNode.Tag);
            sTarget = ((TreeNodeDBMgr)treeView1.SelectedNode).Target;

            //处理按钮
            sTabData = node1.sTabDataNameS.Split(';');
            sP_ID = node1.sTabDataIDS.Split(';');
            int btn_left = 5;
            int btn_top = 5;
            int panel_Height = 35;
            if (btnTab != null && btnTab.Count > sTabData.Length)
            {
                for (int i = btnTab.Count - 1; i >= sTabData.Length - 1; i--)
                {
                    if (i >= sTabData.Length)
                    {
                        btnTab[i].Dispose();
                        btnTab.RemoveAt(i);
                    }

                }
            }
            //btnTab = new Button[sTabData.Length];
            for (int i = 0; i < sTabData.Length; i++)
            {
                if (btnTab.Count <= i || btnTab[i] == null)
                {
                    Button btn_tem = new Button();
                    btn_tem.Click += new EventHandler(btnTabClick);
                    btn_tem.Parent = panel5;
                    btn_tem.Tag = i;
                    btnTab.Add(btn_tem);
                }

                if (btn_left + 150 > panel5.Width)
                {
                    btn_left = 5;
                    btn_top += 27;
                    panel_Height = btn_top + 30;
                }

                if (btnTab[i].Text != sTabData[i])
                {
                    btnTab[i].Text = sTabData[i];
                }

                btnTab[i].Width = 155;
                btnTab[i].Height = 25;

                btnTab[i].Top = btn_top;
                btnTab[i].Left = btn_left;

                btn_left += 160;

            }

            panel5.Height = panel_Height;

            //设置按钮文本
            for (int i = 0; i < btnTab.Count; i++)
            {
                string sTxt = sTabData[i];
                if (sTarget != "")
                {
                    sTxt = sTxt.Replace("{ID}", sTarget);
                }

                if (btnTab[i].Text != sTxt)
                {
                    btnTab[i].Text = sTxt;
                }
            }
        }

        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (tabControl1.SelectedIndex == 1)
            {
                btn_Resize();
            }
        }

        public void showFieldWindow(DataSet ds_Tem)
        {
            if (ds_Tem.Tables.Count > 0)
            {
                TreeNodeDBMgr node1 = (TreeNodeDBMgr)treeView1.SelectedNode; ;
                fdbrow.field_Ref(ado1, node1.sTabName, ds_Tem, 0);
                fdbrow.Show();
            }
        }

        private DataSet getSelectNode()
        {
            TreeNodeDBMgr node1 = (TreeNodeDBMgr)treeView1.SelectedNode;
            string sID = Convert.ToString(node1.Tag);
            string strSQL = "select * from " + node1.dbInf.sTable + " where " + node1.sIDCol + "='" + sID + "'";
            DataSet ds1 = ado1.sel1(strSQL);
            //CDebug.Send(strSQL + "/n-- 返回结果个数: " + ado1.ds_count);
            return ds1;
        }

        /// <summary>
        /// 加载数据 点击树节点
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            CDebug.EnterMethod("点击树列表，加载数据");
            try
            {
                //图标不变
                treeView1.SelectedNode.SelectedImageIndex = treeView1.SelectedNode.ImageIndex;

                TreeNodeDBMgr node1 = (TreeNodeDBMgr)treeView1.SelectedNode;

                //转换连接字符串
                strConReplace();

                if (node1.i_Typ == 1)
                {
                    foreach (object obj1 in lst1)
                    {
                        if (obj1 is Label) ((Label)obj1).Dispose();
                        if (obj1 is Button) ((Button)obj1).Dispose();
                        if (obj1 is TextBox) ((TextBox)obj1).Dispose();
                    }

                    try
                    {
                        ds1 = getSelectNode();
                        showFieldWindow(ds1);
                    }
                    catch (System.Exception ex)
                    {
                        CDebug.SendError(ex.ToString());
                    }

                    refChildTabName_btn();

                    refChildTab_grid();


                    //创建数据编辑按钮
                    if (btnCtrl.Count == 0)
                    {
                        string[] sCap2 = new string[] { "写入", "更新", "删除", "刷新" };
                        for (int i = 0; i < sCap2.Length; i++)
                        {
                            if (btnCtrl.Count <= i || btnCtrl[i] == null)
                            {
                                Button btn = new Button();
                                btnCtrl.Add(btn);

                                btnCtrl[i].Tag = 20 + i;
                                btnCtrl[i].Top = 5;
                                btnCtrl[i].Left = i * 85 + 5;
                                btnCtrl[i].Width = 80;
                                btnCtrl[i].Text = sCap2[i];
                                btnCtrl[i].Parent = panel3;
                                btnCtrl[i].Click += new EventHandler(btn_Click);

                            }
                        }
                        panel3.Height = 30;
                    }

                }

            }
            catch (System.Exception ex)
            {
                CDebug.SendError(ex.ToString());
            }
            CDebug.ExitMethod("点击树列表，加载数据");
        }

        /// <summary>
        /// 替换连接字符串中的数据库名称
        /// </summary>
        public void strConReplace()
        {
            /*
            string strDB_Temp = CPub.findStrBetween(ado1.S_Con, "Catalog=", ";");

            if (dbInf.sDBNam == "")
                ado1.S_Con = ado1.S_Con.Replace("Catalog=;", "Catalog=" + node1.dbInf.sDBNam + ";");
            else
                ado1.S_Con = ado1.S_Con.Replace(strDB_Temp, node1.dbInf.sDBNam);

            ado2.S_Con = ado1.S_Con;
            */

            TreeNodeDBMgr node1 = (TreeNodeDBMgr)treeView1.SelectedNode;
            string sDBConStr = CDB.getConStr(node1.dbInf);
            ado1.S_Con = sDBConStr;
            ado2.S_Con = sDBConStr;
            CDebug.Send(sDBConStr);
        }

        /// <summary>
        /// 双击编辑数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (CDB.dsIsNull(ado2.ds)) return;

                int i_r = e.RowIndex;
                CDebug.Send("RowIndex: " + i_r);

                if (ado2.ds.Tables.Count > 0)
                {
                    FDBRow fdbrow = new FDBRow();
                    fdbrow.StartPosition = FormStartPosition.CenterScreen;
                    fdbrow.field_Ref(ado2, sTabData[Tab_Index], ds2, i_r);
                    fdbrow.ShowDialog();
                }

                if (ado2.ds.Tables[0].Columns[1].Caption != "Title") return;

            }
            catch (System.Exception ex)
            {
                CDebug.SendError(ex.ToString());
                CDebug.Send("核对站号：", ex);
                MessageBox.Show(ex.ToString());
            }
        }

        /// <summary>
        /// 绘制行号
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(e.RowBounds.Location.X,
                e.RowBounds.Location.Y,
                dataGridView1.RowHeadersWidth - 4,
                e.RowBounds.Height);

            TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
                dataGridView1.RowHeadersDefaultCellStyle.Font,
                rectangle,
                dataGridView1.RowHeadersDefaultCellStyle.ForeColor,
                TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
        }

        private void FDBTree_Resize(object sender, EventArgs e)
        {
            //自动调整按钮位置
            btn_Resize();

        }

        /// <summary>
        /// 调整子表查询按钮布局
        /// </summary>
        public void btn_Resize()
        {
            //自动调整按钮位置
            if (btnTab != null && btnTab.Count > 0 && panel5.Width > btnTab[0].Width)
            {
                int btn_left = 5;
                int btn_top = 5;
                int panel_Height = 35;

                for (int i = 0; i < btnTab.Count; i++)
                {
                    if (btn_left + btnTab[i].Width > panel5.Width)
                    {
                        btn_left = 5;
                        btn_top += 27;
                        panel_Height = btn_top + 30;
                    }

                    btnTab[i].Top = btn_top;
                    btnTab[i].Left = btn_left;

                    btn_left += 160;
                }

                panel5.Height = panel_Height;
            }
        }

        /// <summary>
        /// 右键菜单——树目录
        /// </summary>
        /// <param name="treeInfo"></param>
        public void fill_Item(DBTreeInfo treeInfo)
        {
            btnMove.DropDownItems.Clear();

            ToolStripMenuItemII menu = new ToolStripMenuItemII();
            menu.Text = @"\";
            menu.Tag = treeInfo.sRootID;
            menu.ImageIndex = 0;
            menu.sTabName = treeInfo.sTabName;
            menu.ID = treeInfo.sRootID;
            menu.sIDCol = treeInfo.sIDCol;
            menu.sName = treeInfo.sName;
            menu.sPreCol = treeInfo.sPreCol;
            menu.sRootID = treeInfo.sID;
            menu.sOrderID = treeInfo.sOrderID;
            ctree.fillMenu(btnMove, menu);

        }

        /// <summary>
        /// 右键——树目录编辑——鼠标事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnItem_Click(object sender, EventArgs e)
        {

            string s_btn = "";
            if (sender is ToolStripMenuItem)
            {
                s_btn = Convert.ToString(((ToolStripMenuItem)sender).Tag);
                contextMenuStrip1.Close();
                MessageBox.Show(s_btn);
            }

        }

        /// <summary>
        /// 给右键菜单注册事件
        /// </summary>
        /// <param name="node1"></param>
        public void regEvent_item_click(ToolStripMenuItemII node1)
        {
            foreach (ToolStripMenuItemII node2 in node1.DropDownItems)
            {
                node2.Click += new EventHandler(btnItem_Click);
                regEvent_item_click(node2);
            }
        }
    }
}